package com.e1xp.deport_management_system.interceptor;

import com.e1xp.deport_management_system.entity.User;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author E1xP@foxmail.com
 * @version 1.0
 * @PACKAGE_NAME com.e1xp.deport_management_system.interceptor
 * @CLASS_NAME LoginInterceptor
 * @Description TODO 登陆拦截器
 * @Date 2021/4/24 下午 2:37
 **/
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user=(User) request.getSession().getAttribute("user");
        if(user==null){
            response.sendRedirect("/user/preLogin");//跳转到登陆前检查（Cookie处理
            return false;
        }
        return true;
    }
}
